package com.mall.untils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sf.json.JSONObject;

public class ResponseJsonUtil {

	private static Logger logger = LoggerFactory.getLogger(ResponseJsonUtil.class);
	
	/**
	 * 返回网络响应的json数据
	 * @param data
	 * @return
	 */
	public static String responseSuccess(Object data){
		
		logger.debug("response data ==============>\n" + data);
		
		JSONObject result = new JSONObject();
		result.put("response_status", Constants.ResponseStatus.OK);
		result.put("response_data", data==null ? "":data);
		
		return result.toString();
	}
	
	
//	/**
//	 * 请求处理出错，返回的提示信息
//	 * @param errorCode	出错码
//	 * @param data	没什么出错特别提示，该参数可以不给
//	 * @return
//	 */
//	public static String responseFailed(int errorCode , Object data){
//        JSONObject result = new JSONObject();
//        result.put("response_status", Constants.ResponseStatus.ERROR);
//        result.put("response_error_code", errorCode);
//        result.put("response_error_message", Constants.ErrorMessageMap.getKdgnNews(errorCode));
//        result.put("response_data", data);
//
//        return result.toString();
//    }


    public static String responseDefineFailed(String message){
        JSONObject result = new JSONObject();
        result.put("response_status", Constants.ResponseStatus.ERROR);
        result.put("response_error_code", 0);
        result.put("response_error_message", message);
        result.put("response_data", "");
        return result.toString();
    }
}
